package com.rafkind.radicaldatagrid 
{
	import flash.events.Event;
	import mx.controls.HScrollBar;
	import mx.controls.scrollClasses.ScrollBar;
	import mx.controls.VScrollBar;
	import mx.core.UIComponent;
	import mx.events.FlexEvent;
	
	/**
	 * ...
	 * @author Dave Rafkind
	 */
	public class RadicalDataGrid extends UIComponent
	{
		public var verticalScroll:VScrollBar;
		public var horizontalScroll:HScrollBar;
		public var grid:Grid;
		
		public function RadicalDataGrid() {
			super();
		}
		
		override protected function createChildren():void {
			
			super.createChildren();
			if (!grid) {
				grid = new Grid();
				addChild(grid);
			}
			
			if (!verticalScroll) {
				verticalScroll = new VScrollBar();
				addChild(verticalScroll);
			}
			
			if (!horizontalScroll) {
				horizontalScroll = new HScrollBar();
				addChild(horizontalScroll);
			}
		}
		
		override protected function updateDisplayList(unscaledWidth:Number, unscaledHeight:Number):void {
			super.updateDisplayList(unscaledWidth, unscaledHeight);
			
			var scrollBarWidth:int = verticalScroll.measuredWidth;
			var scrollBarHeight:int = horizontalScroll.measuredHeight;			
			
			var gridWidth:int = unscaledWidth - scrollBarWidth;
			var gridHeight:int = unscaledHeight - scrollBarHeight;
			
			grid.move(0, 0);
			grid.setActualSize(gridWidth, gridHeight);
			
			verticalScroll.move(gridWidth, 0);
			verticalScroll.setActualSize(scrollBarWidth, gridHeight);
			
			horizontalScroll.move(0, gridHeight);
			horizontalScroll.setActualSize(gridWidth, scrollBarHeight);
		}
	}
}